#include <unistd.h>
#include <error.h>
#include <stdio.h>

int glob = 6;
char buf[] = "a write to stdout\n";

int main(void) {
	int var;
	pid_t pid;

	var = 88;
	int size_len = sizeof(buf);
	if (write(STDOUT_FILENO, buf, size_len - 1) != size_len - 1) {
		perror("write error");
		exit(1);
	}

	printf("before fork\n");    /* we don't flush stdout */
	if ((pid = fork()) < 0) {
		perror("fork error");
		exit(1);
	} else if (pid == 0) { // child
		glob++;
		var++;
	} else { // parent
		sleep(2);
	}

	printf("pid = %d, glob = %d, var = %d\n", getpid(), glob, var);

	return 0;
}